/**
 * Created by Administrator on 2017/3/13 0013.
 */
var resource;
var pixiStageW=1136;
var pixiStageH=640;

function PSP(ImageName){
    return new PIXI.Sprite(resource[ImageName+".png"].texture);
}
Main2={
    Create:function(){
        var main={};
        var stage = new PIXI.Container();
       var  renderer = PIXI.autoDetectRenderer(256, 256,{antialias:true,transparent:true,resolution:1});
        renderer.view.style.border = "0px dashed black";
        renderer.resize(666,666);
        renderer.backgroundColor=0x000000;

        // document.body.appendChild(renderer.view);
        document.getElementById('pixiContainer').appendChild(renderer.view);


        //资源加载
        var hajime=Hajime2.Create();
        document.addEventListener('HajimeCompleted2',HajimeCompleted);
        function HajimeCompleted(e){
            resource=e.detail;
            setup();
        }

        pageVer=new PIXI.DisplayObjectContainer();

        var sp_verbg =new PIXI.Sprite.fromImage('images/pageInfo_bg.png');
        sp_verbg.x=0;
        sp_verbg.y=0;
        pageVer.addChild(sp_verbg);

        var sp_help =new PIXI.Sprite.fromImage('images/verHelp.png');
        sp_help.anchor.set(0.5);
        sp_help.x=1136/2;
        sp_help.y=740/2-120;
        pageVer.addChild(sp_help);

        TweenMax.to(sp_help,1,{rotation:90*Math.PI/180,ease:Back.easeInOut,yoyo:true,repeat:-1,repeatDelay:1});

        // new TWEEN.Tween({rotation:0})
        //     .to({rotation:180*Math.PI/180},2000)
        //     .onUpdate(function () {
        //         sp_help.rotation=this.rotation;
        //     })
        //     .easing(TWEEN.Easing.Back.InOut)
        //     .delay(500)
        //     .yoyo(true)
        //     .repeat(Infinity)
        //     .start();

        var sp_vert0 =new PIXI.Sprite.fromImage('images/ver_t0.png');
        sp_vert0.anchor.set(0.5);
        sp_vert0.scale.x=sp_vert0.scale.y=0.8;
        sp_vert0.x=1136/2;
        sp_vert0.y=740/2+120;
        pageVer.addChild(sp_vert0);

        //页面适配
        resizeHandler();
        window.onresize = resizeHandler;
        function resizeHandler() {
            renderer.resize(window.innerWidth, window.innerHeight);
            mode='noBorder';
            switch (mode) {
                case 'exactFit':
                    stage.scale.x = window.innerWidth / pixiStageW;
                    stage.scale.y = window.innerHeight / pixiStageH;
                    break;
                case 'noBorder':
                    stage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerWidth / pixiStageW) : (window.innerHeight / pixiStageH);
                    stage.scale.y = stage.scale.x;
                    break;
                case 'noScale':
                    stage.scale.x = 1;
                    stage.scale.y = 1;
                    break;
                case 'showAll':
                    stage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerHeight / pixiStageH) : (window.innerWidth / pixiStageW);
                    stage.scale.y = stage.scale.x;
                    break;
            }
            stage.x = (window.innerWidth - pixiStageW * stage.scale.x) * .5;
            stage.y = (window.innerHeight - pixiStageH * stage.scale.y) * .5;

            if(window.innerWidth>window.innerHeight)
            {
                if(pageVer)
                {
                    stage.addChild(pageVer);
                }

            }
            else
            {
                if(pageVer&&pageVer.parent)
                {
                    stage.removeChild(pageVer);
                }
            }
        };

        stage.addChild(hajime.ReturnWhole());



        // var sp=new PIXI.Graphics();
        // sp.beginFill(0xff0000,1);
        // sp.draw(0,0,1136,800);
        // stage.addChild(sp);
        // sp.alpha=0;

        tt= new PIXI.Text('0%',{fontFamily : 'Arial', fontSize: 20, fill : 0xcccccc, align : 'center'});
        tt.anchor.x=0.5;
        tt.anchor.y=0.5;
        tt.x = pixiStageW/2;
        tt.y = pixiStageH/2+80;
        // stage.addChild(tt);

        document.addEventListener("getText",function(e){
            // tt.text=e.detail;
        })


        var p=new PIXI.Sprite.fromImage('images/Hint.png');
        stage.addChild(p);
        p.alpha=0;
        document.addEventListener("wrongDirection",function(e){
            if(e.detail==1){
                // p.alpha=0;
            }
            else {
                // p.alpha=1;
            }
        })
        //程序开始
        function setup(){
            console.log("Start!");
            //控制页面

            //加载页面在正式页面之上
            // document.getElementById("container").style.zIndex=6;
            // document.getElementById("pixiContainer").style.top="0px";
        };









        //渲染层
        gameLoop();
        function gameLoop(){
            requestAnimationFrame(gameLoop);
            //Render The Stage
            renderer.render(stage);
        }
        return main;
    }
}
